function getTestItemsManagePanel(t) {return new CMS.TestItemsManagePanel(t)};
var TEST_ITEMS_MANAGE_PANEL;
CMS.TestItemsManagePanel = function(title) {
	TEST_ITEMS_MANAGE_PANEL = this;
	var objArr = converArr([
		{name:"id",hidden:true} , {name:'name' , width:240 , sortable:true , header:'测试项目名称'},
		{name:'id',header:'操作',width:120, renderer:function(v) {
			return '<a href="javascript:TEST_ITEMS_MANAGE_PANEL.editInfo(' + pub_edit_option + ')">编辑</a> ' 
			+  '<a href="javascript:TEST_ITEMS_MANAGE_PANEL.deleteRow()">删除</a>';
		}}
	] , true);
	var nameSearch = getField({width:190,name:'name'});
	var ds = getPageDs(sys_basdata_url + 'getTestItems' , 'id' , objArr);
	var pageBar = getPageBBar(20 , ds);
	CMS.TestItemsManagePanel.superclass.constructor.call(this, {
		title:title,store:ds,view:getGridView('没有找到数据'),
		columns:objArr.columns,sm:getRowModel(),bbar:pageBar,
		id:'test_items_manager_panel',tbar:['-',{
			text:'测试项目名称：'
		},nameSearch ,'-',{
			text:'查询',iconCls:'searchIcon2',handler:function() {TEST_ITEMS_MANAGE_PANEL.refresh()}
		},'-' ,{
			text:'新增',iconCls:'add',handler:function() {
				TEST_ITEMS_MANAGE_PANEL.editInfo(pub_add_option);
			}
		},'-']
	});
	this.refresh = function() {
       ds.load({params:{start:0,limit:pageBar.pageSize}});
    };
    registPageDsParams(ds , [nameSearch] , TEST_ITEMS_MANAGE_PANEL.refresh);
    TEST_ITEMS_MANAGE_PANEL.refresh();
    //编辑
    this.editInfo = function(type) {
    	var dWidth = 340;
    	var items = [
    		getHidden({name:'id',allowNull:true}),
    		getField({width:dWidth,name:'name',fieldLabel:'测试项目名称'})
    	];
    	pubEditRow(type ,items , TEST_ITEMS_MANAGE_PANEL , '测试项目' , 120 , 600 , sys_basdata_url + 'saveTestItem', TEST_ITEMS_MANAGE_PANEL.refresh);
    };
    
    //删除
    this.deleteRow = function() {
    	pubDeleteRow(TEST_ITEMS_MANAGE_PANEL , 'name' , '测试项目' , sys_basdata_url + 'saveTestItem' , ds , TEST_ITEMS_MANAGE_PANEL.refresh);
    };
};
Ext.extend(CMS.TestItemsManagePanel, Ext.grid.GridPanel);

// 变更类别
function getChangeTypesManagePanel(t) {return new CMS.ChangeTypesManagePanel(t)};
var CHANGE_TYPES_MANAGE_PANEL;
CMS.ChangeTypesManagePanel = function(title) {
	CHANGE_TYPES_MANAGE_PANEL = this;
	var objArr = converArr([
		{name:"id",hidden:true} , {name:'name' , width:120 , sortable:true , header:'变更类别名称'},
		{name:'productLineName' , width:120 , sortable:true , header:'所属产业线'},
		//{name:'phase' , width:50 , sortable:true , header:'阶段'},
		{name:'createdByName' , width:120 , sortable:true , header:'创建人'},
		{name:'createdDate' , width:120 , sortable:true , header:'创建时间'},
		{name:'lastModifiedByName' , width:120 , sortable:true , header:'最后修改人'},
		{name:'lastModifiedDate' , width:120 , sortable:true , header:'最后修改时间'},
		{name:'isPublishedString' , width:60 , sortable:true , header:'是否发布'},
		{name:"isPublished",hidden:true} , 
		{name:'id',header:'操作',width:360, renderer:function(v,c,row) {
			var data = row.data;
			var isPublished = data['isPublished'];
			var ret;
			if(isPublished==2){
				ret = '<a href="javascript:CHANGE_TYPES_MANAGE_PANEL.editInfo(' + pub_edit_option + ')">编辑</a> ' 
					+  '<a href="javascript:CHANGE_TYPES_MANAGE_PANEL.deleteRow()">删除</a> '
					+  '<a href="javascript:CHANGE_TYPES_MANAGE_PANEL.setTestItems()">设置实验项目</a> '
					+  '<a href="javascript:CHANGE_TYPES_MANAGE_PANEL.viewTestItems()">查看实验项目</a> '
					+  '<a href="javascript:CHANGE_TYPES_MANAGE_PANEL.isPublish(1)">发布</a>';
				return ret;
			}
			else{
				return '<a href="javascript:CHANGE_TYPES_MANAGE_PANEL.isPublish(2)">取消发布</a>';
			}
		}}
	] , true);
	var nameSearch = getField({width:190,name:'name'});
	var ds = getPageDs(sys_basdata_url + 'getChangeTypes' , 'id' , objArr);
	var pageBar = getPageBBar(20 , ds);
	CMS.ChangeTypesManagePanel.superclass.constructor.call(this, {
		title:title,store:ds,view:getGridView('没有找到数据'),
		columns:objArr.columns,sm:getRowModel(),bbar:pageBar,
		id:'change_types_manager_panel',tbar:['-',{
			text:'变更类别名称：'
		},nameSearch ,'-',{
			text:'查询',iconCls:'searchIcon2',handler:function() {CHANGE_TYPES_MANAGE_PANEL.refresh()}
		},'-' ,{
			text:'新增',iconCls:'add',handler:function() {
				CHANGE_TYPES_MANAGE_PANEL.editInfo(pub_add_option);
			}
		},'-']
	});
	this.refresh = function() {
       ds.load({params:{start:0,limit:pageBar.pageSize}});
    };
    registPageDsParams(ds , [nameSearch] , CHANGE_TYPES_MANAGE_PANEL.refresh);
    CHANGE_TYPES_MANAGE_PANEL.refresh();
    //编辑
    this.editInfo = function(type) {
    	var dWidth = 340;
    	var items = [
    		getHidden({name:'id',allowNull:true}),
    		getField({width:dWidth,name:'name',fieldLabel:'变更类别名称'})
    		//createNormlCommon(dWidth , change_level_type , '阶段' , '' , false, 'phase')
    	];
    	pubEditRow(type ,items , CHANGE_TYPES_MANAGE_PANEL , '变更类别' , 120 , 600 , sys_basdata_url + 'saveChangeType', CHANGE_TYPES_MANAGE_PANEL.refresh);
    };
    
    //删除
    this.deleteRow = function() {
    	pubDeleteRow(CHANGE_TYPES_MANAGE_PANEL , 'name' , '变更类别' , sys_basdata_url + 'saveChangeType' , ds , CHANGE_TYPES_MANAGE_PANEL.refresh);
    };
    
    // 设置实验项目
    this.setTestItems = function() {
    	var changeTypeId = CHANGE_TYPES_MANAGE_PANEL.getSelectionModel().getSelected().data['id'];
    	
    	var checkPanel = getTempCheckProxy(
    		{url:sys_basdata_url + 'getTestItemsByChangeType?type=1&id=' + changeTypeId,autoLoad:true},
    		{url:sys_basdata_url + 'getTestItemsByChangeType?type=2&id=' + changeTypeId,autoLoad:true},
    		400,
    		[
    			{name:'id',hidden:true},
    			{name:'name',width:120,header:'实验项目名称'}
    		],'备选角色' , '已选角色' , getBt('请选择角色') , function() {
    			var checkTestItems = [] ,index = 0;
    			forEachDs(checkPanel.ds2 , function(row) {
    				checkTestItems[index++] = row['id'];
    			});
    			ajax({
    				url:sys_basdata_url + "saveChangeTypeTestItems",
    				params:{changeTypeId:changeTypeId,testItems:checkTestItems},
    				success:function(resp) {
    					ajaxSuc(resp);
    					checkPanel.win.close();
    				}
    			})
    		}
    	);
    };
    
    // 查看实验项目
    var panelObj;
    this.viewTestItems = function(){
    	panelObj = this;	
    	var row = CHANGE_TYPES_MANAGE_PANEL.getSelectionModel().getSelected().data;
    	var changeId = row['id'];
    	var arr = converArr([
    		{name:'changeTypeId',hidden:true},{name:'testItemsId',hidden:true},
    		{name:'isMust',hidden:true},
    		{name:'testItemsName',width:120,header:'实验项目名称'},
    		{name:'isMustString',width:50,header:'必须?'},
    		{name:'changeTypeId',header:'操作',width:360, renderer:function(v,c,row) {
    			var data = row.data;
				var isMust = data['isMust'];
				if(isMust==2)
					return '<a href="javascript:CHANGE_TYPES_MANAGE_PANEL.setIsMust(1,'+changeId+','+data['testItemsId']+')">必须</a> '
				else
					return '<a href="javascript:CHANGE_TYPES_MANAGE_PANEL.setIsMust(2,'+changeId+','+data['testItemsId']+')">可选</a> '
			}}
    	],true);
		var grid = getGrid(null , arr , 
	    		{url:sys_basdata_url + "viewChangeTypeTestItems?changeTypeId="+row['id'] , autoLoad:true},{region:'center'});
	    var win = getEmptyPanel3([] , '查看:[' + row['name'] + ']实验项目' , grid , 400 , 600 , CHANGE_TYPES_MANAGE_PANEL);
	  
		this.refreshInternal = function(){
	    	grid.getStore().load();
	    }
    };
    // 修改必选可选
	this.setIsMust = function(isMust, changeTypeId, testItem){
	   	ajax({
    		url:sys_basdata_url + "updateIsMust",
    		params:{changeTypeId:changeTypeId,testItemId:testItem,isMust:isMust},
    		success:function(resp) {
    			panelObj.refreshInternal();
    		}
    	});
	}
	
	// 发布变更类别
	this.isPublish = function(isPublish){
		var changeTypeId = CHANGE_TYPES_MANAGE_PANEL.getSelectionModel().getSelected().data['id'];
		ajax({
    		url:sys_basdata_url + "publish",
    		params:{id:changeTypeId,isPublished:isPublish},
    		success:function(resp) {
    			ajaxSuc(resp);
    			CHANGE_TYPES_MANAGE_PANEL.refresh();
    		}
    	});
	}
};
Ext.extend(CMS.ChangeTypesManagePanel, Ext.grid.GridPanel);